﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.IO;

namespace PPSignSDKDemoSharp
{
    /// <summary>
    /// Interaction logic for showImageDlg.xaml
    /// </summary>
    public partial class showImageDlg : Window
    {
        public showImageDlg()
        {
            InitializeComponent();
          
 
            if (System.IO.File.Exists(strfile + strfilename))
            {
               // Uri uri = new Uri(strfile + strfilename);
               // imagebmp.Source = new BitmapImage(uri); //new Uri("pack://siteOfOrigin:,,,/image/3.bmp")

            string strSrc = strfile + strfilename;
            if (File.Exists(strSrc))
            {
                System.Drawing.Image img = System.Drawing.Image.FromFile(strfile + strfilename);
                MemoryStream ms = new MemoryStream();
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                ms.Position = 0;
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.StreamSource = ms;
                bi.EndInit();

                imagebmp.Source = bi;
                img.Dispose();
              }
            else
            {
                System.Windows.MessageBox.Show("Load Image Failed"/*" 加载签名图像失败或没有生成签名图像！"*/, "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                button1.IsEnabled = false;
            }
          /*    BinaryReader read = new BinaryReader(File.Open(strfile + strfilename, FileMode.Open));
                FileInfo fi = new FileInfo(strfile + strfilename);
                Byte[] bytes = read.ReadBytes((int)fi.Length);
                read.Close();
                 
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.StreamSource = new MemoryStream(bytes);
                bi.EndInit();
                imagebmp.Source = bi;*/
            }

        }
        private static string strfile = System.Environment.GetEnvironmentVariable("TEMP");
        private static string strfilename = "\\PPSignTempImage.bmp"; 
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string strSrc = strfile + strfilename;
            if (File.Exists(strSrc))
            {
                FolderBrowserDialog dlg = new FolderBrowserDialog();
                dlg.SelectedPath = "c:";
                dlg.Description = "请选择保存pfx文件的目录";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
                string strDes = dlg.SelectedPath + "\\";
                strDes += "test.bmp";

                File.Copy(strSrc, strDes,true);
            }
            Close();
            
        }
        ///Application.Current.MainWindow
        private void img_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            Point centerPoint = e.GetPosition(this);
            this.sfr.CenterX = centerPoint.X;
            this.sfr.CenterY = centerPoint.Y;
            if (sfr.ScaleX < 0.3 && sfr.ScaleY < 0.3 && e.Delta < 0)
            {
                return;
            }
            sfr.ScaleX += (double)e.Delta / 3500;
            sfr.ScaleY += (double)e.Delta / 3500;  
        }


    }
}
